﻿<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ include file="/inc.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>闪耀先生系列 - 确认订单</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<!-- Bootstrap -->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
<!-- style -->
<link href="<%=basePath%>css/home.css" rel="stylesheet" />
</head>
<body>
	<div class="alert alert-danger" role="alert" id="error"
		style="display: none">
		<i class="fa fa-exclamation-triangle"></i> gggggggg
	</div>
	<s:if test='error != null'>
		<div class="error">
			<div class="alert alert-danger" role="alert">
				<i class="fa fa-exclamation-triangle"></i>
				<s:property value="error" />
			</div>
		</div>
		<!--E .error-->
	</s:if>
	<form class="form-horizontal" id="form"
		action="<%=basePath%>public/orderAction!pay.action" method="post"
		encType="multipart/form-data">
		<s:hidden name="stlye_id"></s:hidden>
		<s:hidden name="cloth_id"></s:hidden>
		<s:hidden name="btn_id"></s:hidden>
		<s:hidden name="call"></s:hidden>
		<s:hidden name="trade_in"></s:hidden>
		<s:hidden name="height"></s:hidden>
		<s:hidden name="weight"></s:hidden>
		<s:hidden name="size"></s:hidden>
		<s:hidden name="size2"></s:hidden>
		<s:hidden name="positive"></s:hidden>
		<s:hidden name="back"></s:hidden>
		<s:hidden name="text"></s:hidden>
		<s:hidden name="images1"></s:hidden>
		<s:hidden name="images2"></s:hidden>
		<s:hidden name="openid"></s:hidden>
		<s:hidden name="fd4sm"></s:hidden>
		<s:hidden name="fd4cs"></s:hidden>
		<s:hidden name="brand_id"></s:hidden>
		<s:hidden name="name"></s:hidden>
		<s:hidden name="phone"></s:hidden>
		<s:hidden name="address"></s:hidden>

		<div class="container-fluid">
			<div class="wrap">
				<div class="order-list">
					<div class="row">
						<h3>面料</h3>
						<div class="col-xs-3">
							<img src="<%=basePath_org%><s:property value="cloth.img" />"
								alt="">
						</div>
						<div class="col-xs-9">
							<div class="name">
								<s:property value="cloth.name" />
							</div>
							<p class="red">
								价格：
								<s:property value="brand.price" />
								元
							</p>
						</div>
					</div>

					<div class="row">
						<h3>款式</h3>
						<div class="col-xs-3">
							<img src="<%=basePath_org%><s:property value="stlye.img" />"
								alt="">
						</div>
						<div class="col-xs-9">
							<div class="name">
								<span class="red">款式详情：</span>
								<s:property value="stlye.name" />
							</div>
						</div>
					</div>

				</div>
				<!--E .order-list-->
				<div class="dizhi">
					<h3>会员信息</h3>
					<div class="form-group has-error">
						<s:property value="name" />
					</div>
					<div class="form-group has-error">
						<s:property value="address" />
					</div>
					<div class="form-group has-error">
						<s:property value="phone" />
					</div>
				</div>
				<!--E .dizhi-->
				<button type="button" class="btn btn-org btn-lg btn-block"
					onclick="CreateOrder()">微信支付</button>
			</div>
			<!--E .wrap-->

		</div>
	</form>
	<script src="<%=basePath%>js/jquery-1.10.1.min.js"></script>

	<script>
function CreateOrder() {
            	 
            	
			 var stlye_id = document.getElementById('stlye_id').value;
			 var cloth_id = document.getElementById('cloth_id').value;
			 var btn_id = document.getElementById('btn_id').value;
			 var call = document.getElementById('call').value;
			 var trade_in = document.getElementById('trade_in').value;
			 var height = document.getElementById('height').value;
			 var weight = document.getElementById('weight').value;
			 var size = document.getElementById('size').value;
			 var positive = document.getElementById('positive').value;
			 var back = document.getElementById('back').value;
			 var text = document.getElementById('text').value;
			 var images1 = document.getElementById('images1').value;
			 var images2 = document.getElementById('images2').value;
			 var openid = document.getElementById('openid').value;
			 var fd4sm = document.getElementById('fd4sm').value;
			 var fd4cs = document.getElementById('fd4cs').value;
			 var phone = document.getElementById('phone').value;
			 var name = document.getElementById('name').value;
			 var address = document.getElementById('address').value;
			 var openid = document.getElementById('openid').value;
			 
				$.ajax({
								type:'post',
								url:'<%=basePath%>public/orderAction!pay.action',
								dataType : 'json', 
								data : {"fd4cs":fd4cs,"fd4sm":fd4sm,"stlye_id":stlye_id,"cloth_id":cloth_id,"btn_id":btn_id,"call":call,"trade_in":trade_in,"height":height,"weight":weight,"size":size,"positive":positive,"back":back,"text":text,"name":name,"address":address,"phone":phone,"images1":images1,"images2":images2,"openid":openid},
								timeout:60000,
								success: function (json_str){
									var temp = eval(json_str);  
									  if(temp.code != "success"){
										  alert(temp.message);
									  }else{
										  WeixinJSBridge.invoke('getBrandWCPayRequest',
											  	   {
											  	   "appId" : temp.appId,     //公众号名称，由商户传入     
										           "timeStamp":temp.timeStamp,         //时间戳，自1970年以来的秒数     
										           "nonceStr" : temp.nonceStr, //随机串     
										           "package" : temp.package,     
										           "signType" : "MD5",         //微信签名方式:     
										           "paySign" : temp.paySign//微信签名 
											  	   },
											  	  function(res){
							                          if(res.err_msg == "get_brand_wcpay_request:ok" ) {
							                        	//交易成功
							                        	  _updateOrder(temp.fdOrderId);
							                          }else{
							                          	alert("交易失败!"+fd4sm);
							                          }
							                          // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
							                          //因此微信团队建议，当收到ok返回时，向商户后台询问是否收到交易成功的通知，若收到通知，前端展示交易成功的界面；若此时未收到通知，商户后台主动调用查询订单接口，查询订单的当前状态，并反馈给前端展示相应的界面。
						                          }); 
									  }
									
									
								},		       
						        error: function(jqXHR , textStatus , errorThrown){
						        	window.location.href = "${pageContext.request.contextPath}/wx/login.jsp";
						        }
				});
}  
function checkOrder(){
	var brand_id = document.getElementById('brand_id').value;
	var openid = document.getElementById('openid').value;
	$.ajax({
		type:'post',
		url:'<%=basePath%>public/orderAction!checkOrder.action',
		dataType : 'json', 
		data : {"brand_id":brand_id,"openid":openid},
		timeout:60000,
		success: function (json_str){
			var temp = eval(json_str); 
			if(temp.code != "success"){
				alert(temp.message);
			}else{
				CreateOrder();
			}
			
		}
	});
}	
function _updateOrder(fdOrderId){
	var openid = document.getElementById('openid').value;
	 $.ajax({
			type:'post',
			url:'<%=basePath%>public/orderAction!updateOrder.action',
				dataType : 'json',
				data : {
					"fdOrderId" : fdOrderId,"openid":openid
				},
				timeout : 60000,
				success : function(json_str) {
					 var temp = eval(json_str);  
					 //alert(temp.message);
					 location.href = "${pageContext.request.contextPath}/public/brandAction!view.action";
				}
			});
		}
	</script>
	</script>

</body>
</html>